package com.example.work3.itm_fengchuang;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.work3.R;

import java.util.List;

public class WeatherAdapter extends RecyclerView.Adapter<WeatherAdapter.ViewHolder>{
    private List<item_fengzhuang> list;
    private Context context;
    public WeatherAdapter( Context context,List<item_fengzhuang> list) {
        this.context = context;
        this.list = list;
    }
    @NonNull
    @Override
    public WeatherAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_one,parent,false);
        return new WeatherAdapter.ViewHolder(itemView);
    }

    @Override
    public void onBindViewHolder(@NonNull WeatherAdapter.ViewHolder holder, int position) {

        item_fengzhuang weather = list.get(position);
        holder.item_date.setText(weather.getDate());
        holder.item_temp.setText(weather.getTemp()+"°");
        holder.item_windDir.setText(weather.getWindDir());
        holder.item_windLevel.setText(weather.getFive()+"级");
    }

    @Override
    public int getItemCount() {
        return list.size();
    }
    public class ViewHolder extends RecyclerView.ViewHolder {
        TextView item_date,item_temp,item_windDir,item_windLevel;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            item_date = itemView.findViewById(R.id.TextDayone);
            item_temp = itemView.findViewById(R.id.TextDayfour);
            item_windDir = itemView.findViewById(R.id.TextDayfive);
            item_windLevel = itemView.findViewById(R.id.TextDaythere);

        }
    }
}
